#include <set>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    int i;
    int ia[5] = { 0, 1, 2, 3, 4 };
    set<int> iset(ia, ia + 5);

    cout << "size=" << iset.size() << endl; // size=5
    cout << "3 count=" << iset.count(3) << endl; // 3 count=1
    iset.insert(3);
    cout << "size=" << iset.size() << endl; // size=5
    cout << "3 count=" << iset.count(3) << endl; // 3 count=1
    iset.insert(5);
    cout << "size=" << iset.size() << endl; // size=6
    cout << "3 count=" << iset.count(3) << endl; // 3 count=1
    iset.erase(1);
    cout << "size=" << iset.size() << endl; // size=5
    cout << "3 count=" << iset.count(3) << endl; // 3 count=1
    cout << "1 count=" << iset.count(1) << endl; // 1 count=0

    set<int>::iterator ite1 = iset.begin();
    set<int>::iterator ite2 = iset.end();
    for (; ite1 != ite2; ++ite1)
        cout << *ite1 << " ";
    cout << endl; // 0 2 3 4 5

    // 使用STL算法find()来搜寻元素，可以有效运作，但不是好办法
    ite1 = find(iset.begin(), iset.end(), 3);
    if (ite1 != iset.end())
        cout << "3 found" << endl; // 3 found
    ite1 = find(iset.begin(), iset.end(), 1);
    if (ite1 == iset.end())
        cout << "1 not found" << endl; // 1 not found
    
    // 面对关联式容器，应该使用其所提供的find函数来搜寻元素
    ite1 = iset.find(3);
    if (ite1 != iset.end())
        cout << "3 found" << endl;
    
    ite1 = iset.find(1);
    if (ite1 == iset.end())
        cout << "1 not found" << endl;
    
    // error -> try to change set 元素
    // *ite1 = 9;

    return 0;
}